<route lang="json5" type="page">
{
    layout: "default",
    style: {
        navigationBarTitleText: "推荐详情",
    },
}
</route>

<template>
    <view class="m-base-box m-recommend-detail pt-4">
        <wd-card>
            <view class="flex flex-col items-start gap-1 pt-2 pb-4 w-[100%]">
                <wd-text :text="info?.title" bold size="18px" color="#000"></wd-text>
                <view class="flex justify-between items-center mt-2 w-[100%]">
                    <view>
                        <wd-text
                            :text="timeFormat(info?.updateTime, 'yyyy-mm-dd')"
                            size="12px"
                            color="#949090"
                            prefix="最后更新："
                        ></wd-text
                    ></view>
                    <view>
                        <wd-text
                            :text="timeFormat(info?.createTime, 'yyyy-mm-dd')"
                            size="12px"
                            color="#949090"
                            prefix="发布时间："
                        ></wd-text
                    ></view>
                </view>
            </view>
        </wd-card>
        <wd-card title="介绍" class="mt-4">
            <view class="pb-4">
                <uv-parse :content="info?.content"></uv-parse>
            </view>
        </wd-card>
    </view>
</template>

<script lang="ts" setup>
const info = ref<any>({});
function timeFormat(date: any, format: string) {
    if (!date) return;
    if (!format) format = "yyyy-MM-dd";
    switch (typeof date) {
        case "string":
            date = new Date(date.replace(/-/g, "/"));
            break;
        case "number":
            date = new Date(date);
            break;
    }
    if (!(date instanceof Date)) return;
    let dict = {
        yyyy: date.getFullYear(),
        M: date.getMonth() + 1,
        d: date.getDate(),
        H: date.getHours(),
        m: date.getMinutes(),
        s: date.getSeconds(),
        MM: ("" + (date.getMonth() + 101)).substr(1),
        dd: ("" + (date.getDate() + 100)).substr(1),
        HH: ("" + (date.getHours() + 100)).substr(1),
        mm: ("" + (date.getMinutes() + 100)).substr(1),
        ss: ("" + (date.getSeconds() + 100)).substr(1),
    };
    return format.replace(/(yyyy|MM?|dd?|HH?|ss?|mm?)/g, function () {
        return dict[arguments[0]];
    });
}
onLoad(() => {
    uni.getStorage({
        key: "recommendedDetail",
        success: function (res) {
            info.value = res?.data || {};
        },
    });
});
</script>

<style lang="scss" scoped>
.m-recommend-detail {
    padding-bottom: 32rpx;
}
</style>
